import math

class ParameterContainer(object):
    def __init__(self, pars, names):
        if len(names) != len(pars):
            msg = "ParameterContainer constructor expects two equal-length sequences,"
            msg += " got sequences of length {0} (`names') and {1} (`pars')."
            raise Exception(msg.format(len(names), len(pars)))

        self._d = dict([(name, pars[i]) for i, name in enumerate(names)])
        self._names = names
        self._pars = pars

    def __getitem__(self, i):
        if type(i) == type("burp!"):
            return self._d[i]
        else:
            return self._pars[i]

    def __len__(self, i):
        return len(names)


        

class FitStatistics(object):
    def __init__(self, frange, x, y, initpars, fitpars, init_chi2_dof,
                 final_chi2_dof, ndof, success, msg, cov, par_names = None):

        self.frange             = frange
        self.x                  = x
        self.y                  = y
#        if par_names:
#            self.initpars       = ParameterContainer(initpars, par_names)
#            self.fitpars        = ParameterContainer(fitpars, par_names)
#        else:
        self.initpars       = initpars                        
        self.fitpars        = fitpars
            

        self.init_chi2_dof      = init_chi2_dof
        self.final_chi2_dof     = final_chi2_dof
        self.ndof               = ndof
        self.success            = success
        self.cov                = cov
        self.msg                = msg

        self.par_names          = par_names
        
        self.errpars            = []

        for i in xrange(len(fitpars)):
            self.errpars.append(math.sqrt(self.cov[i][i]))


        
